package com.itheima.demo1inetaddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressDemo1 {
    public static void main(String[] args) {

        try {
//        获取本机IP对象
            InetAddress address= InetAddress.getLocalHost();
            System.out.println(address.getHostAddress());
            System.out.println(address.getHostName());
////         获取对方的IP对象
            InetAddress address1= InetAddress.getByName("172.19.0.1");
            System.out.println(address1.getHostAddress());
            System.out.println(address1.getHostName());
////        判断本机与对方主机是否互通
            System.out.println(address1.isReachable(100));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
